<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <!-- <div class="indexTitle">楼幢管理</div> -->
                    <div class="contentsize">经营查询</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <!-- 出租经营 -->
                <el-form ref="czjyform" :model="czjyform" label-width="80px" :inline="true" size="mini">
                    <el-form-item label="房屋地址:">
                        <div style="width:190px">
                            <el-input v-model="czjyform.fwdz" placeholder="请输入房屋地址" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width:190px">
                            <el-input v-model="czjyform.dabh" placeholder="请输入档案编号" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="产权单位:">
                        <div style="width:190px">
                            <el-input v-model="czjyform.cqdw" placeholder="请输入产权单位" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="承租人:">
                        <div style="width:190px">
                            <el-input v-model="czjyform.czr" placeholder="请输入承租人" @keyup.enter.native="onSearch"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="产别:">
                        <div style="width:190px">
                            <el-select v-model="czjyform.cb" placeholder="请选择产别" clearable @change="onSearch">
                                <el-option v-for="item in cblist" :key="item.code" :label="item.name" :value="item.code">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="状态:">
                        <div style="width:190px">
                            <el-select v-model="czjyform.jyzt" placeholder="请选择状态" clearable @change="onSearch">
                                <el-option v-for="item in ztlist" :key="item.code" :label="item.name" :value="item.code">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch('czjyform')" icon="el-icon-search"
                            class="searchcolor">查询</el-button>
                        <el-button @click="reSearch('czjyform')" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                        <el-button type="primary" @click="downloadlist" icon="el-icon-download"
                            class="searchcolor">导出</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="330" -->
            <el-table :data="czjytableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                    :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor" border :max-height="maxHeight">
                <el-table-column prop="dabh" label="档案编号" align="center"> </el-table-column>
                <el-table-column prop="qs" label="区属" align="center" width="80px"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center">
                    <template slot-scope="scope">
                        <span style="font-weight: 700;color: #409ee1;">
                            {{ scope.row.fwdz }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column prop="cqdw" label="产权单位" align="center" width="220px"> </el-table-column>
                <el-table-column prop="cb" label="产别" align="center" width="100px"> </el-table-column>
                <!-- <el-table-column prop="zjdj" label="租金单价" align="center"> </el-table-column> -->
                <!-- <el-table-column prop="htje" label="合同金额" align="center"> </el-table-column> -->
                <!-- <el-table-column prop="jzmj" label="建筑面积" align="center"> </el-table-column> -->
                <!-- <el-table-column prop="zldqsj" label="租赁到期时间" align="center" width="120">
                    <template slot-scope="scope">
                        {{ scope.row.zldqsj ? scope.row.zldqsj.split(' ')[0] : '' }}
                    </template>
                </el-table-column> -->
                <el-table-column prop="signid" label="状态" align="center" width="80">
                    <template slot-scope="scope">
                        {{ scope.row.jyzt==1 ? '出租' : '招租中' }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="100" align="center">
                    <template slot-scope="scope">
                        <router-link :to="{ name: 'wthtdetail', params: { id: scope.row.id, signid: scope.row.signid } }"
                        v-if="scope.row.jyzt==1">
                            <el-button type="text" size="small">详情</el-button>
                        </router-link>
                        <!-- <router-link :to="{ name: 'addht', params: { id: scope.row.id } }" style="padding:0 12px"
                                    v-if="!scope.row.signid">
                                    <el-button type="text" size="small">新订合同</el-button>
                                </router-link> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="czjytotal"
                    :current-page.sync="czjycurrent" :page-size="pageSize"
                    @current-change="(val) => handleCurrentChange('czjyform', val)">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { projectList, projectdelete, signlist, jygllist, wtyylist,exportwtyylist } from '@/api/index';
import valueList from '@/components/common/valueList.vue'
export default {
    name: 'wtdalist',
    data() {
        return {
            cblist: valueList.cblist,
            qslist: valueList.qslist,//区属
            cqdwlist: valueList.cqdwlist,//产权单位
            ztlist: valueList.ztlist,//状态
            activeName: 'first',
            total: 0,
            current: 1,
            wtjytotal: 0,
            wtjycurrent: 1,
            czjytotal: 0,
            czjycurrent: 1,
            pageSize: 10,
            form: {
                cb: "",
                cqdw: "",
                create_name: "",
                create_name_id: "",
                create_time: "",
                current: 1,
                dabh: "",
                fwdz: "",
                glfs: "办公自用",
                id: "",
                jyglid: "",
                jzmj: "",
                pageSize: 10,
                qs: "",
                status_code: 0,
                type: this.$store.getters.gfdw == '房产经理部' ? '1' : '2',//1房间 2楼
                update_name: "",
                update_name_id: "",
                update_time: ""
            },
            wtjyform: {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dabh: '',//档案编号 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jyzt: '',//经营状态 0：招租中 1：出租 ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                stdwmc: '',//受托单位
            },
            czjyform: {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dabh: '',//档案编号 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jyzt: '',//经营状态 0：招租中 1：出租 ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                stdwid: this.$store.getters.company,//受托单位ID
            },
            tableData: [],
            czjytableData: [],
            wtjytableData: [],
            maxHeight:null
        };
    },
    components: {},
    computed: {
        // 判断变色
        getcolorred(zt) {
            console.log(zt);
            return (zt) => {
                if (zt == "已出租") {
                    return { color: "#19BE6B", fontWeight: 700 };
                } else {
                    return { color: "#409ee1", fontWeight: 700 };
                }
            };
        },
    },
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black'
        },
        tablecellColor(){
            return "font-weight:700;color:#000000;border-color:#c0c0c0";
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row' //这是类名
            } else {
                return ''
            }
        },
        // 换页
        handleCurrentChange(myParam, val) {
            this.czjycurrent = val;
            this.czjyform.current = val;
            this.wtyylist(this.czjyform);
        },
        // 搜索
        onSearch(myParam) {
            this.czjycurrent = 1;
            this.czjyform.current = 1;
            this.wtyylist(this.czjyform);
        },
        // 重置
        reSearch(myParam) {
            this.czjycurrent = 1;
            this.czjyform = {
                cb: '',//产别 ,
                cqdw: '',//产权单位 ,
                create_time: '',//创建时间 ,
                current: 1,//第几页 ,
                dabh: '',//档案编号 ,
                fwdz: '',//地址 ,
                id: '',//id ,
                jyzt: '',//经营状态 0：招租中 1：出租 ,
                jzmj: '',//建筑面积 ,
                pageSize: 10,//每页数量 ,
                qs: '',//区属 ,
                stdwid: this.$store.getters.company,//受托单位
            };
            this.wtyylist(this.czjyform);
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    projectdelete(data).then((res) => {
                        if (res.code == 200) {
                            this.wtyylist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 出租经营列表
        wtyylist(data) {
            wtyylist(data).then((res) => {
                if (res.code == 200) {
                    this.czjytableData = res.data.records;
                    this.czjytotal = res.data.total;
                } else {
                    this.czjytableData = [];
                    this.czjytotal = 0;
                }
            });
        },
        // 办公自用列表
        jygllist(data) {
            jygllist(data).then((res) => {
                // console.log('res',res)
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 委托运营
        cwtdwsignlist(data) {
            wtdwsignlist(data).then((res) => {
                // console.log('res',res)
                if (res.code == 200) {
                    this.wtjytableData = res.data.records;
                    this.wtjytotal = res.data.total;
                } else {
                    this.wtjytableData = [];
                    this.wtjytotal = 0;
                }
            });
        },
        // 导出
        downloadlist() {
            exportwtyylist(this.czjyform).then(res => {
                console.log(res)
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: 'application/vnd.ms-excel'
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = '委托运营导出文件';
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res)
            })
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 400
        })
        // this.projectList(this.form);
        // this.wtdwsignlist(this.wtjyform)
        this.wtyylist(this.czjyform)
        // this.jygllist(this.form)
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 250px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
